package com.csw.scala;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;

public class Demo19JavaWordCount {
    public static void main(String[] args) throws Exception{

        //使用hashmap存储最终的结果
        HashMap<String, Integer> hashMap = new HashMap<>();

        //读取文件
        BufferedReader br = new BufferedReader(new FileReader("Scala/data/words.txt"));
        String line;
        while ((line=br.readLine())!=null){
            String[] words = line.split(",");

            for (String word : words) {

                if (hashMap.containsKey(word)){
                    Integer integer = hashMap.get(word);
                    hashMap.put(word,integer+1);
                }else{
                    hashMap.put(word,1);
                }
            }
        }
        System.out.println(hashMap);
    }
}
